﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：WF_STEP实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class WF_STEP
    {
        private decimal m_dec_i_buzhouid;

        private decimal m_dec_i_chengnuots;

        private decimal m_dec_i_liuchengid;

        private decimal m_dec_i_paigong;

        private string m_str_s_buzhoubh;

        private string m_str_s_buzhoumc;

        private string m_str_s_buzhouurl;

        private string m_str_s_caozuoff;

        /// <summary>
        ///     步骤ID(自增量)
        /// </summary>
        public decimal I_BUZHOUID
        {
            get { return m_dec_i_buzhouid; }
            set { m_dec_i_buzhouid = value; }
        }

        /// <summary>
        ///     流程ID
        /// </summary>
        public decimal I_LIUCHENGID
        {
            get { return m_dec_i_liuchengid; }
            set { m_dec_i_liuchengid = value; }
        }

        /// <summary>
        ///     步骤编号
        /// </summary>
        public string S_BUZHOUBH
        {
            get { return m_str_s_buzhoubh; }
            set { m_str_s_buzhoubh = value; }
        }

        /// <summary>
        ///     步骤URL
        /// </summary>
        public string S_BUZHOUURL
        {
            get { return m_str_s_buzhouurl; }
            set { m_str_s_buzhouurl = value; }
        }

        /// <summary>
        ///     承诺天数
        /// </summary>
        public decimal I_CHENGNUOTS
        {
            get { return m_dec_i_chengnuots; }
            set { m_dec_i_chengnuots = value; }
        }

        /// <summary>
        ///     操作方法
        /// </summary>
        public string S_CAOZUOFF
        {
            get { return m_str_s_caozuoff; }
            set { m_str_s_caozuoff = value; }
        }

        /// <summary>
        ///     步骤名称
        /// </summary>
        public string S_BUZHOUMC
        {
            get { return m_str_s_buzhoumc; }
            set { m_str_s_buzhoumc = value; }
        }

        /// <summary>
        ///     是否派工
        /// </summary>
        public decimal I_PAIGONG
        {
            get { return m_dec_i_paigong; }
            set { m_dec_i_paigong = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class WF_STEPProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public WF_STEPProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据WF_STEP实体添加或者修改WF_STEP信息
        /// </summary>
        public bool InsertOrUpdate(WF_STEP WF_STEP, OracleTransaction Transaction)
        {
            if (WF_STEP.I_BUZHOUID == 0)
                InsertWF_STEP(WF_STEP, Transaction);
            else
                UpdateWF_STEP(WF_STEP, Transaction);
            return WF_STEP.I_BUZHOUID == 0 ? false : true;
        }

        /// <summary>
        ///     根据WF_STEP实体添加或修改WF_STEP信息
        /// </summary>
        public bool InsertOrUpdate(WF_STEP WF_STEP)
        {
            return InsertOrUpdate(WF_STEP, null);
        }


        /// <summary>
        ///     根据WF_STEP主键删除WF_STEP信息
        /// </summary>
        /// <param name="I_BUZHOUID"></param>
        public bool DeleteWF_STEP(decimal I_BUZHOUID, OracleTransaction Transaction)
        {
            var spName = "CS_DelWF_STEP";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = I_BUZHOUID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据WF_STEP主键删除WF_STEP信息
        /// </summary>
        /// <param name="I_BUZHOUID"></param>
        public bool DeleteWF_STEP(decimal I_BUZHOUID)
        {
            return DeleteWF_STEP(I_BUZHOUID, null);
        }

        /// <summary>
        ///     根据条件删除WF_STEP信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteWF_STEPsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelWF_STEPsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除WF_STEP信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteWF_STEPsDynamic(string WhereClause)
        {
            return DeleteWF_STEPsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据WF_STEP主键选择WF_STEP信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_STEP信息</returns>
        public WF_STEP SelectWF_STEP(decimal I_BUZHOUID, OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEP";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = I_BUZHOUID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var WF_STEP = PopulateWF_STEP(rd);
                rd.Close();
                return WF_STEP;
            }
            return null;
        }

        /// <summary>
        ///     根据WF_STEP主键选择WF_STEP信息
        /// </summary>
        /// <returns>WF_STEP信息</returns>
        public WF_STEP SelectWF_STEP(decimal I_BUZHOUID)
        {
            return SelectWF_STEP(I_BUZHOUID, null);
        }

        /// <summary>
        ///     选择所有WF_STEP信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有WF_STEP信息</returns>
        public DataTable SelectWF_STEPsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有WF_STEP信息
        /// </summary>
        /// <returns>所有WF_STEP信息</returns>
        public DataTable SelectWF_STEPsAll()
        {
            return SelectWF_STEPsAll(null);
        }

        /// <summary>
        ///     根据条件选择WF_STEP信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_STEP信息</returns>
        public DataTable SelectWF_STEPsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择WF_STEP信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>WF_STEP信息</returns>
        public DataTable SelectWF_STEPsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectWF_STEPsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择WF_STEP信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_STEP信息</returns>
        public DataTable SelectWF_STEPsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择WF_STEP信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>WF_STEP信息</returns>
        public DataTable SelectWF_STEPsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectWF_STEPsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新WF_STEP字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateWF_STEPsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdWF_STEPDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新WF_STEP字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateWF_STEPsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateWF_STEPsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertWF_STEP(WF_STEP WF_STEP, OracleTransaction Transaction)
        {
            var spName = "CS_InsWF_STEP";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WF_STEP.I_LIUCHENGID;
            storedParams[1].Value = WF_STEP.S_BUZHOUBH;
            storedParams[2].Value = WF_STEP.S_BUZHOUURL;
            storedParams[3].Value = WF_STEP.I_CHENGNUOTS;
            storedParams[4].Value = WF_STEP.S_CAOZUOFF;
            storedParams[5].Value = WF_STEP.S_BUZHOUMC;
            storedParams[6].Value = WF_STEP.I_PAIGONG;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            WF_STEP.I_BUZHOUID = Convert.ToInt32(storedParams[7].Value);
            return result;
        }

        private bool UpdateWF_STEP(WF_STEP WF_STEP, OracleTransaction Transaction)
        {
            var spName = "CS_UpdWF_STEP";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WF_STEP.I_LIUCHENGID;
            storedParams[1].Value = WF_STEP.S_BUZHOUBH;
            storedParams[2].Value = WF_STEP.S_BUZHOUURL;
            storedParams[3].Value = WF_STEP.I_CHENGNUOTS;
            storedParams[4].Value = WF_STEP.S_CAOZUOFF;
            storedParams[5].Value = WF_STEP.S_BUZHOUMC;
            storedParams[6].Value = WF_STEP.I_PAIGONG;
            storedParams[7].Value = WF_STEP.I_BUZHOUID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private WF_STEP PopulateWF_STEP(IDataReader dr)
        {
            var WF_STEP = new WF_STEP();
            WF_STEP.I_BUZHOUID = dr["I_BUZHOUID"] == DBNull.Value ? 0 : (decimal) dr["I_BUZHOUID"];
            WF_STEP.I_LIUCHENGID = dr["I_LIUCHENGID"] == DBNull.Value ? 0 : (decimal) dr["I_LIUCHENGID"];
            WF_STEP.S_BUZHOUBH = dr["S_BUZHOUBH"] == DBNull.Value ? "" : (string) dr["S_BUZHOUBH"];
            WF_STEP.S_BUZHOUURL = dr["S_BUZHOUURL"] == DBNull.Value ? "" : (string) dr["S_BUZHOUURL"];
            WF_STEP.I_CHENGNUOTS = dr["I_CHENGNUOTS"] == DBNull.Value ? 0 : (decimal) dr["I_CHENGNUOTS"];
            WF_STEP.S_CAOZUOFF = dr["S_CAOZUOFF"] == DBNull.Value ? null : (string) dr["S_CAOZUOFF"];
            WF_STEP.S_BUZHOUMC = dr["S_BUZHOUMC"] == DBNull.Value ? "" : (string) dr["S_BUZHOUMC"];
            WF_STEP.I_PAIGONG = dr["I_PAIGONG"] == DBNull.Value ? 0 : (decimal) dr["I_PAIGONG"];
            return WF_STEP;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion